home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 43
/
Amiga Format CD43 (1999)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-09].iso
/
-serious-
/
comms
/
other
/
rxsocket
/
examples
/
echottcp.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1999-06-14
|
1KB
|
59 lines
/*
A very simple echo T/TCP client.
Show how to make a basic connection to a tcp service
in T/TCP and came back to TCP if it doesn't work.
To test it on localhost, be sure echo/tcp is enabeld
in the services and inetd database, then write
rx echotcp localhost.
*/
l="rmh.library";if ~show("L",l) then;if ~addlib(l,0,-30) then exit
if AddLibrary("rexxsupport.library","rxsocket.library")~=0 then exit
prg = ProgramName("NOEXT")
if ~RMH_ReadArgs("HOST/A") then do
call PrintFault(IoErr(),prg)
exit
end
addr = resolve(parm.0.value)
if addr=="-1" then call err "no host <"parm.0.value">"
if ~getservbyname("SE","echo","tcp") then
call err "echo tcp service not found"
sin.AddrFamily = "INET"
sin.AddrAddr = addr
sin.AddrPort = se.ServPort
sock = socket("INET","STREAM","IP")
if sock<0 then call err "no socket ("errno()")"
request = "echo service test"
dottcp=1
if sendto(sock,REQUEST,"EOF","SIN")~=length(REQUEST) then do
err=Errno()
if err==57 then dottcp=0
else call err "send error ("errno()")"
end
if dottcp==0 then do
say "(back to TCP)"
if connect(sock,"SIN")<0 then call err "connect error ("errno()")"
if send(sock,REQUEST)~=length(REQUEST) then call err "send error ("errno()")"
end
if recv(sock,"BUF",256)<0 then
call err "recv error ("errno()")"
say buf
exit
err: procedure expose prg
parse arg msg
say prg":" msg
exit